package cn.edu.cqu.bysj.wm.gui.table;


import java.util.Collections;
import java.util.List;

import javax.swing.JOptionPane;

import mySwingToolkit.controller.TableController;
import mySwingToolkit.model.ClassModel;
import mySwingToolkit.model.SwitchedTableModel;
import mySwingToolkit.ui.TableView;
import cn.edu.cqu.bysj.wm.gui.result.DepthQRow;

public class DepthQView extends TableView<DepthQRow>{
	/**
	 * create depth and Q view table
	 * @param title
	 */
	public DepthQView(String title){
		//构造
		super(new SwitchedTableModel<DepthQRow>(
				new Object[][] {
				},
				new String[] {
						"深度", "Q值", "社区数量"
				},
				new Class[] {
						Integer.class, Double.class, Integer.class
				},
				new boolean[] {
						false, false, false
				},
				false, false, false,20
				){
			@Override
			public Object[] translate(
					ClassModel<DepthQRow> object) {
				DepthQRow c=object.getObject();
				
				return new Object[]{object,this.getRowCount()+1,c.getDepth(),c.getQ(),c.getCommunityNumber()};
			}
			@Override
			public DepthQRow constructObject(int row,
					int col) {
				@SuppressWarnings("unchecked")
				ClassModel<DepthQRow> cm=(ClassModel<DepthQRow>) this.getValueAt(row, 0);
				DepthQRow cr=null;
				if(cm!=null){
					cr=cm.getObject();
				}else{
					cr=new DepthQRow();
				}
				switch(col){
				case 2:
					break;
				case 3:
					break;
				case 4:
					break;
				case 5:
					break;
				case 6:
					break;
				}
				return cr;
			}
			@Override
			public void initNullRow(int row) {
				//this.setValueAt("男", row, 4);
			}
		},title
		);
		//加入数据
		this.initDatas(Collections.singletonList(new DepthQRow()));
		//设置tc
		this.setTableController(new TableController<DepthQRow>(){
			@Override
			public List<DepthQRow> getBackupDatas(
					SwitchedTableModel<DepthQRow> tm) {
				JOptionPane.showMessageDialog(null, "暂不支持");
				return null;
			}
			@Override
			public boolean saveChanges(SwitchedTableModel<DepthQRow> tm) {
				System.out.println(tm.getInsertDatas().size());
				return true;
			}
		});
	}
	

}
